define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hkj/index' + location.search,
                    set_url: 'hkj/set',
                    multi_url: 'hkj/multi',
                    import_url: 'hkj/import',
                    table: 'disease',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'disease_id',
                sortName: 'weight',
                maintainSelected: true,//跨页选择模式

                // fixedColumns: true,
                // fixedRightNumber: 1,
                // sidePagination: "client",
                // pagination: false,//开启分页
                // search: true, //开启刷选
                // pageSize:10,
                // maintainSelected :true,//全段分页
                // dataField:'rows',
                columns: [
                    [
                        {checkbox: true,formatter:function(value, row, index) {
                                var hyj= Config.hyj;
                                var id = row.disease_id;
                                if(hyj){
                                    if(hyj.indexOf(id) != -1){
                                        return {checked : true};
                                    }
                                }
                            }
                        },
                        {field: 'disease_id', title: 'ID'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'first_name', title: '首字母', operate: false},
                        {field: 'weight', title: __('权重')},
                    ]
                ]
            });
            //管理
            $(".btn-process-1").click(function(){
                var hos_id= Config.hos_id;
                var off_id = Config.off_id;
                var ids = Table.api.selectedids(table);
                layer.confirm('确定要更新数据吗?', {btn: ['是','否'] },
                    function(index){
                        layer.close(index);
                        $.post("hkj/set", {off_id:off_id,hos_id:hos_id,ids:ids},function(response){
                            if(response.code == 1){
                                Toastr.success(response.msg);
                                $(".btn-refresh").trigger('click');
                                table.bootstrapTable('refresh');
                            }else{
                                Toastr.error(response.msg);
                            }
                        }, 'json');
                    },
                    function(index){
                        layer.close(index);
                    }
                );
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
